package com.example.demo.controller;

import com.example.demo.Server.Look_for_jobServer;
import com.example.demo.entity.JobPosition;
import com.example.demo.result.PageResult;
import com.example.demo.result.Result;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
public class Look_for_job_Controller {
    @Autowired
    private Look_for_jobServer look_for_jobServer;

    @PostMapping("/select_job")
    public Result<ArrayList> Look_for_jon() {



        ArrayList<JobPosition> jobPositions = look_for_jobServer.select_Look_for_jon();

        return Result.success(jobPositions);
    }
    @PostMapping("/add_job")
    public Result<Integer> add_job(@RequestBody  JobPosition jobPosition) {
        int result = look_for_jobServer.add_job(jobPosition);
        return Result.success(result);
    }
    @DeleteMapping("/delete_job")
    public Result<Integer> delete_job( Integer id) {
        int result = look_for_jobServer.delete_job(id);
        return Result.success(result);
    }
    @PostMapping("/update_job")
    public Result<Integer> update_job(@RequestBody JobPosition jobPosition) {
        int result = look_for_jobServer.update_job(jobPosition);
        return Result.success(result);
    }
    @GetMapping("/select_job_page")
    public Result<PageResult> select_job_page(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) Integer hrId,
            JobPosition jobPosition) {

        // 安全处理 hrId
        int safeHrId = hrId == null ? 0 : hrId;

        // 调用 Service 查询分页数据
        PageResult pageResult = look_for_jobServer.select_Look_for_jon_page(page, size, safeHrId, jobPosition);

        return Result.success(pageResult);
    }



}
